//
// client.cpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//


#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <iostream>
#include <vector>

#include <Object.h>
#include <Locker.h>

#include "Thread.h"

#include "rpcexception.h"
#include "rpcprotocol.h"
#include "event.h"
#include "message_handler.h"
#include "session_boost.h"

#include "rpcclient_default.h"


int main(int argc, char* argv[])
{
  try
  {
    // Check command line arguments.
    if (argc < 3)
    {
      std::cerr << "Usage: client <host> <port>" << std::endl;
      return 1;
    }

    //wayixia::client client(io_service, argv[1], argv[2]);
    rpc::client_default rpcclient;
    rpcclient.connect(argv[1], argv[2], 1000000);

    rpc::client::iservice_proxy* s;
    s = rpcclient.get_service("test_service");
    std::string action;
    while(std::getline(std::cin, action)) {
      // get code
      if(action == "exit")
        break;

      try {
        rpc::protocol::response res;
        rpc::parameters params;
        params["p0"] = 10;
        params["p1"] = 22;
        rpcclient.call(s, action, params, res);
        res.dump();
      }  
      catch (const std::exception& e2)
      {
        std::cerr << e2.what() << std::endl;
      }	  
    }
  }
  catch (const std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}
